import Vue from 'vue'
import VueRouter from 'vue-router'
// 引入模块化的路由
const files = require.context('./modules', false, /\.router.js$/);

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originalPush.call(this,location).catch(err=> err)
}

const routes = []
// 遍历模块化路由中的数据一条一条添加进routes
files.keys().forEach(key => {
  routes.push(...files(key).default);
});
const router = new VueRouter({
  routes
})



export default router
